.NET Core Interview Questions and Answers for 10+ Years Experienced Professionals

 

🔹 Core Concepts

Q1. What are the key differences between .NET Framework, .NET Core, and .NET 5/6/7+?
Answer:

  • .NET Framework – Windows-only, older, supports legacy apps.

  • .NET Core – Cross-platform (Windows, Linux, macOS), modular, open-source, better performance.

  • .NET 5+ (unified platform) – Combines .NET Core and .NET Framework into one platform with continuous updates (no ".NET Core 4").


Q2. Explain the Middleware pipeline in ASP.NET Core.
Answer:

  • Middleware is a software component that processes HTTP requests and responses.

  • It forms a pipeline where each component can handle, pass, or short-circuit a request.

  • Example:

    app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
  • Custom middleware can be added using app.Use(...).


Q3. What are Hosting Models in .NET Core?
Answer:

  • In-Process hosting – App runs inside IIS worker process (w3wp.exe), better performance.

  • Out-of-Process hosting – App runs as a separate process (dotnet.exe) with IIS as a reverse proxy.

  • Self-hosted (Kestrel only) – Runs without IIS, often used in Docker or Linux environments.


🔹 Advanced & Architecture

Q4. How do you implement Dependency Injection (DI) in .NET Core?
Answer:

  • Built-in DI container (IServiceCollection).

  • Register services:

    services.AddTransient<IService, Service>(); services.AddScoped<IService, Service>(); services.AddSingleton<IService, Service>();
  • Lifetime depends on usage:

    • Transient – new instance every time.

    • Scoped – one per request.

    • Singleton – one per application lifetime.


Q5. How do you handle Configuration in .NET Core?
Answer:

  • Configuration is hierarchical and supports multiple providers: JSON, environment variables, secrets, Azure Key Vault.

  • Example:

    var builder = WebApplication.CreateBuilder(args); var myValue = builder.Configuration["MySettings:Key"];

Q6. Explain the difference between IHostedService and BackgroundService.
Answer:

  • IHostedService – Base contract for long-running tasks.

  • BackgroundService – Abstract class simplifying background task creation by overriding ExecuteAsync.

  • Example use cases: background jobs, message queue processing, cleanup tasks.


🔹 Performance & Optimization

Q7. How do you improve performance in .NET Core applications?
Answer:

  • Use AsNoTracking in EF Core for read-only queries.

  • Implement caching (in-memory, distributed like Redis).

  • Optimize database calls (batch queries, stored procedures).

  • Enable response compression and HTTP/2.

  • Use ValueTask instead of Task when suitable.

  • Minimize memory allocations (e.g., Span<T>, Memory<T>).


Q8. What is the difference between Task, ValueTask, and IAsyncEnumerable?
Answer:

  • Task – standard async operation, always allocates.

  • ValueTask – avoids allocation if operation is already completed. Useful in high-performance scenarios.

  • IAsyncEnumerable<T> – asynchronous streaming, allows processing items as they arrive instead of waiting for the full collection.


🔹 Security & Best Practices

Q9. How do you secure an ASP.NET Core API?
Answer:

  • Use JWT (JSON Web Tokens) for stateless authentication.

  • Implement Role-Based and Policy-Based authorization.

  • Secure secrets with Azure Key Vault or User Secrets.

  • Enable HTTPS redirection, CORS policies, and Data Protection APIs.


Q10. Explain Data Protection in .NET Core.
Answer:

  • Protects sensitive data like cookies, tokens, and CSRF.

  • Provides APIs for encryption and decryption with key rotation.

  • Keys are stored locally or in Azure Key Vault/Redis for distributed systems.


🔹 Cloud & Microservices

Q11. How do you deploy .NET Core apps in Docker and Kubernetes?
Answer:

  • Create a Dockerfile:

    FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base WORKDIR /app COPY . . ENTRYPOINT ["dotnet", "MyApp.dll"]
  • Push image to Azure Container Registry / DockerHub.

  • Deploy using Kubernetes Deployment + Service + Ingress.


Q12. What patterns do you use in microservices with .NET Core?
Answer:

  • API Gateway (e.g., Ocelot).

  • Circuit Breaker (Polly).

  • Event-driven architecture with Kafka/RabbitMQ.

  • CQRS + Event Sourcing for complex domains.

  • Distributed caching for scalability.


🔹 Entity Framework Core

Q13. Difference between EF Core and Dapper?
Answer:

  • EF Core – Full ORM, LINQ, migrations, change tracking, slower but easier.

  • Dapper – Micro ORM, lightweight, faster for raw SQL queries, no change tracking.


Q14. How do you handle migrations in EF Core in production?
Answer:

  • Maintain migrations in version control.

  • Use dotnet ef migrations add and dotnet ef database update.

  • In CI/CD, run migrations automatically or via tools like Flyway/Liquibase for safe rollbacks.


🔹 System Design & Scaling

Q15. How would you design a high-traffic .NET Core API?
Answer:

  • Use Load Balancers + horizontal scaling.

  • Cache frequently accessed data (Redis/Memory).

  • Optimize database with read replicas.

  • Use CQRS to separate read/write workloads.

  • Implement async communication with queues.

  • Deploy with Kubernetes + autoscaling.

Comments

Popular posts from this blog

What are SOLID Principles?

.NET Core Senior Interview Q&A